package com.msmall.community.bbs.action.wml;

import com.msmall.base.exception.AuthorityException;
import com.msmall.base.exception.DataNotFoundException;
import com.msmall.community.bbs.model.Topic;
import com.msmall.community.bbs.service.TopicManager;

public class ManageTopicAction extends BBSBaseAction {

	private static final long serialVersionUID = -6383141867699487097L;
	
	private Topic topic;
	
	private TopicManager topicManager;
	
	public String index(){
		topicManager.getPaginationbyUserid(page, getUserid());
		page.initPageString(getRequest());
		return SUCCESS;
	}
	
	public String delete() throws AuthorityException{
		
		topicManager.delete(topicId, getUserid());
		
		String url = "";
		url = "selfTopicIndex.do?userid=" + getUserid();
		setBbsToUrl(url);

		return SUCCESS;
	}
	
	public String update() throws DataNotFoundException, AuthorityException{
		topic = (Topic) topicManager.getTopic(topicId);
		return SUCCESS;
	}

	public String save() throws DataNotFoundException, AuthorityException{
		topicManager.updateTopic(topic, getUserid(), getUserAgentType());
		String url = "selfTopicIndex.do";
		setBbsToUrl(url);
		return SUCCESS;
	}
	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	public void setTopicManager(TopicManager topicManager) {
		this.topicManager = topicManager;
	}
}
